﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public abstract class UserData_Report : UserData_AddressExt_1
	{
		#region private member variables

		/// <summary>
		/// German: "Meldungsart"
		/// </summary>
		private readonly ReportType_Base _reportTypeBase;

		#endregion private member variables

		#region constructor

		public UserData_Report(byte dataType, byte device, byte address, byte addressAddOn, eAddressExtension_1 addressExtension, ReportType_Base reportTypeBase)
			: base(dataType, device, address, addressAddOn, addressExtension)
		{
			_reportTypeBase = reportTypeBase;
		}

		#endregion constructor

		#region getters

		/// <summary>
		/// German: "Meldungsart"
		/// </summary>
		public ReportType_Base TheReportType { get { return _reportTypeBase; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();

			if (TheReportType != null)
			{
				hashCode ^= TheReportType.GetHashCode();
			}

			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());
			stringBuilder.Append(", ");

			stringBuilder.Append("TheReportType='");
			if (TheReportType != null)
			{
				stringBuilder.Append(TheReportType);
			}
			else
			{
				stringBuilder.Append("<null>");
			}
			stringBuilder.Append("'");

			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				UserData_Report userData2Compare = obj as UserData_Report;
				return EqualsProperties(userData2Compare);
			}

			return false;
		}

		internal bool EqualsProperties(UserData_Report userData2Compare)
		{
			if (base.EqualsProperties(userData2Compare))
			{
				if ((TheReportType != null) && (userData2Compare.TheReportType != null))
				{
					return (TheReportType.Equals(userData2Compare.TheReportType));
				}

				// at least one is null -> both must be null or NOT equal
				return (TheReportType == null) && (userData2Compare.TheReportType == null);
			}

			return false;
		}

		#endregion ToString, Equals, GetHashCode
	}
}
